<template>

	<uni-section type="line">
		<uni-list>
			<view class="main-list" @click="toSigningRecord" v-if="isSign||sign0||sign1||sign2">
				<uni-list-item showArrow class="signList" title="签约记录" thumb="/static/签约 确认签约 电子签约.png"
					thumb-size="medium" :clickable="true">
					<template #footer>
						<span style="color: greenyellow;font-size: 24rpx;" v-if="isSign">已签约</span>
						<span style="color: #2984f8;font-size: 24rpx;" v-else-if="sign2">待支付</span>
						<span style="color: red;font-size: 24rpx;" v-else-if="sign0">被驳回</span>
						<span style="color: yellow;font-size: 24rpx;" v-else-if="sign1">审核中</span>

					</template>
				</uni-list-item>
			</view>
			<view @click="openSign" v-else>
				<uni-list-item showArrow rightText="未签约" title="签约记录" thumb="/static/签约 确认签约 电子签约.png"
					thumb-size="medium" :clickable="true" />
			</view>
			<view @click="openfamilycontrol">
				<uni-list-item showArrow title="家庭成员管理" :clickable="true" thumb="/static/家庭成员管理.png"
					thumb-size="medium" />
			</view>
			<view @click="toHealthRecord">
				<uni-list-item showArrow :clickable="true" title="我的健康档案" thumb="/static/我的健康档案.png"
					thumb-size="medium">
					<template #footer>
						<span style="color: orange;font-size: 24rpx;" v-if="!userStore.userInfo?.IDnumber">未实名</span>
					</template>
				</uni-list-item>
			</view>
			<uni-list-item showArrow :clickable="true" title="我的健康监测" thumb="/static/健康度评定统计.png" thumb-size="medium" />
			<view @click="openSet" v-if="isSign">
				<uni-list-item :clickable="true" showArrow title="我的医生团队" thumb="/static/医生-团队.png"
					thumb-size="medium" />
			</view>
			<view @click="openTeam" v-else>
				<uni-list-item :clickable="true" showArrow title="我的医生团队" thumb="/static/医生-团队.png" thumb-size="medium"
					rightText="未签约" />
			</view>
			<view @click="toMyPackage" v-if="isSign">
				<uni-list-item :clickable="true" showArrow title="我的服务包" thumb="/static/服务包.png" thumb-size="medium" />
			</view>
			<view @click="openPack" v-else>
				<uni-list-item rightText="未签约" :clickable="true" showArrow title="我的服务包" thumb="/static/服务包.png"
					thumb-size="medium" />
			</view>
			<uni-list-item :clickable="true" showArrow title="我的收藏" thumb="/static/收藏.png" thumb-size="medium" />
		</uni-list>
	</uni-section>





	<!-- 未实名 -->
	<uni-popup ref="checkRef" :animation="false" type="center" border-radius="100px 100px 0 0"
		style="text-align: center;">
		<view class="pop-center">
			<view class="pop-tip">
				尚未登记实名信息，是否前往完善？
			</view>
			<view class="pop-done">
				<view style="color: #999;" @click="closeCheck">取消</view>
				<view style="color: #2984f8;" @click="chooCheck">确认</view>
			</view>
		</view>
	</uni-popup>

	<!-- 未签约团队 -->
	<uni-popup ref="teamRef" :animation="false" type="center" border-radius="100px 100px 0 0"
		style="text-align: center;">
		<view class="pop-center">
			<view class="pop-tip">
				暂无已签约团队，是否立即前往签约
			</view>
			<view class="pop-done">
				<view style="color: #999;" @click="closeTeam">再等等</view>
				<view style="color: #2984f8;" @click="chooseTeam">立即前往</view>
			</view>
		</view>
	</uni-popup>
	<!-- 未签约服务包 -->
	<uni-popup ref="packRef" :animation="false" type="center" border-radius="100px 100px 0 0"
		style="text-align: center;">
		<view class="pop-center">
			<view class="pop-tip">
				暂无已签约服务包，是否立即前往签约
			</view>
			<view class="pop-done">
				<view style="color: #999;" @click="closePack">再等等</view>
				<view style="color: #2984f8;" @click="choosePack">立即前往</view>
			</view>
		</view>
	</uni-popup>
	<!-- 无签约记录 -->
	<uni-popup ref="signRef" :animation="false" type="center" border-radius="100px 100px 0 0"
		style="text-align: center;">
		<view class="pop-center">
			<view class="pop-tip">
				暂无已签约记录，是否立即前往签约
			</view>
			<view class="pop-done">
				<view style="color: #999;" @click="closeSign">再等等</view>
				<view style="color: #2984f8;" @click="chooseSign">立即前往</view>
			</view>
		</view>
	</uni-popup>


</template>

<script setup>
	import {
		onMounted,
		ref
	} from 'vue';

	import {
		useUserStore
	} from '../../store/user';
	import {
		onLoad,
	} from '@dcloudio/uni-app';
	import {
		findSignApi
	} from '../../api/sign';

	onMounted(() => {
		getSign()
	})

	const checkRef = ref(null)
	// 打开确认
	function openCheck() {
		checkRef.value.open()
	}
	// 点击确认
	function chooCheck(data) {
		uni.navigateTo({
			url: '/HealthHeadlinesPackage/pages/newHealthRecord/newHealthRecord'
		})
		checkRef.value.close()
	}


	// 取消
	function closeCheck() {
		checkRef.value.close()
	}

	const teamRef = ref(null)
	// 打开确认
	function openTeam() {
		teamRef.value.open()
	}
	// 点击确认
	function chooseTeam() {
		uni.navigateTo({
			url: '/SignPackage/pages/organization/organization'
		})
		teamRef.value.close()
	}
	// 取消
	function closeTeam() {
		teamRef.value.close()
	}

	const packRef = ref(null)
	// 打开确认
	function openPack() {
		packRef.value.open()
	}
	// 点击确认
	function choosePack() {
		uni.navigateTo({
			url: '/SignPackage/pages/organization/organization'
		})
		packRef.value.close()
	}

	// 取消
	function closePack() {
		packRef.value.close()
	}

	const signRef = ref(null)
	// 打开确认
	function openSign() {
		signRef.value.open()
	}
	// 点击确认
	function chooseSign() {
		uni.navigateTo({
			url: '/SignPackage/pages/organization/organization'
		})
	}
	// 取消
	function closeSign() {
		signRef.value.close()
	}

	const userStore = useUserStore()



	//跳转我的医生团队
	function openSet() {
		console.log(1);
		uni.navigateTo({
			url: '/minePackage/pages/TeamSelection/TeamSelection',
		});
	}









	// 跳转健康档案
	function toHealthRecord() {
		if (userStore.userInfo.IDnumber) {
			uni.navigateTo({
				url: '/HealthHeadlinesPackage/pages/HealthRecord/HealthRecord'

			})
		} else {
			openCheck()
		}
	}

	// 跳转服务包
	function toMyPackage() {
		uni.navigateTo({
			url: '/serviceStep/pages/myPacks/myPacks'
		})
	}


	const isSign = ref(0)
	const sign1 = ref(0)
	const sign0 = ref(0)
	const sign2 = ref(0)
	// 判断是否签约
	function getSign() {
		findSignApi({
				residentId: userStore.userInfo?._id
			})
			.then(res => {
				if (res.code == 200) {
					isSign.value = res.data.rows?.filter(item => item.state == 3)?.length
					sign1.value = res.data.rows?.filter(item => item.state == 1)?.length
					sign0.value = res.data.rows?.filter(item => item.state == 0)?.length
					sign2.value = res.data.rows?.filter(item => item.state == 2)?.length
				}
			})
	}




	// //跳转我的医生团队
	// function openSet() {
	// 	uni.navigateTo({
	// 		url: '/minePackage/pages/Team-of-doctors/Team-of-doctors',
	// 	});
	// }

	// 跳转到签约记录
	function toSigningRecord() {
		if (useStore.userInfo?.state == '') {
			uni.showToast({
				title: '您还未签约',
				duration: 1000,
			});
		} else {
			uni.navigateTo({
				url: '/minePackage/pages/signing-progress/signing-progress'
			})
		}
	}

	// 跳转到家庭成员管理
	function openfamilycontrol() {
		uni.navigateTo({
			url: '/minePackage/pages/family-control/family-control',
		})
	}

	//跳转健康检测
	function openHealth() {
		uni.navigateTo({
			url: '/minePackage/pages/MyHealth/MyHealth',
		})
	}
</script>

<style scoped lang="scss">
	.list {
		height: 112rpx;
		line-height: 112rpx;
	}

	.uni-list-item {

		height: 112rpx;
	}



	.signList .sign.uni-list-item__extra-text {
		color: greenyellow !important;
	}

	// 中间弹出层
	.pop-center {
		width: 520rpx;
		height: 352rpx;
		background-color: #fff;
	}

	.pop-tip {
		height: 264rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 32rpx;
		line-height: 56rpx;
		color: #333;
	}

	.pop-done {
		height: 88rpx;
		border-top: 1px solid #e6e6e6;
		display: flex;
	}

	.pop-done view {
		height: 88rpx;
		width: 260rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 32rpx;
	}
</style>
<style>
	.main-list .uni-list-item__content--center .uni-list-item__content-title {
		font-size: 32rpx !important;
		color: #333;
	}

	.pop-center {
		border-radius: 24rpx;
		padding: 0 32rpx;
	}

	.pop-center .pop-tip {
		font-weight: 500;
	}
</style>